// pages/my/message/message.js
let util = require('../../../utils/index')
import http from '../../../services/http/index'
import { ListData } from '../../../utils/Data'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ctype:0,
    tabArr:['订单信息','系统消息','聊天'],
    list:{data:[]}
  },
  chooseTab(e){
    let type = e.currentTarget.dataset.type;
    this.setData({
      ctype:type
    });
    this.getList();
  },
  //详情
  detail(e){
    let id = e.currentTarget.dataset.id;
    let type = this.data.ctype;
    var url = '';
    if(type == 0){
      //订单信息
      let orderid = e.currentTarget.dataset.orderid;
      let ordertype = e.currentTarget.dataset.ordertype;
      var typeindex = 0;
      //ordertype 1:接送机 2班车 3预约用车 4包车
      switch(ordertype){
        case 1:
          typeindex = 0;
              break;
        case 2:
          typeindex=2
          break;
        case 3:
          typeindex=1;
          break;
        case 4:
          typeindex=3
          break;
      }
      url = '../../order/detail/detail?type='+typeindex+'&id=' + orderid;
    };
    if(type == 1){
      //系统消息

    };
    if(type == 2){
      //聊天
      url = './messageChart?id='+id
    }
    util.default.go(url);
  },
  //获取列表
  getList() {
    let type = this.data.ctype;

    if (type ==0){
      //订单信息
      http.myOrderMessage()
          .then(data => {
            this.setData({
              'list': Object.assign(new ListData(), { data: data.list || [], unreadChatTotal: data.unreadChatTotal, unreadOrderTotal: data.unreadOrderTotal, unreadSystemTotal: data.unreadSystemTotal })
            });
          });
    }

    if (type == 1) {
      //系统消息
      http.mySystemMessage()
          .then(data => {
            this.setData({
              'list': Object.assign(new ListData(), { data: data.list || [], unreadChatTotal: data.unreadChatTotal, unreadOrderTotal: data.unreadOrderTotal, unreadSystemTotal: data.unreadSystemTotal })
            });
          });
    }

    if (type == 2) {
      //聊天
      http.myChatMessage()
          .then(data => {
            this.setData({
              'list': Object.assign(new ListData(), { data: data.list || [], unreadChatTotal: data.unreadChatTotal, unreadOrderTotal: data.unreadOrderTotal, unreadSystemTotal: data.unreadSystemTotal })
            });
          });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.setNavigationBarTitle({
      title:'我的消息'
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})